package com.example.my.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBconnection {
    private String FileName;
    private int DBType;
    private Connection conn;
    private String MySqlIDriver;
    private String MySqIURL;
    public DBconnection(){
        conn = null;
    }
    public Connection getConn() {
        DBType = 1;
        switch (DBType){
            case 1:
                return (getConnToMySQL());
            default:return null;
        }
    }
    public Connection getConnToMySQL(){
        try {
            //8.0加.cj 小于5.7不加
            MySqlIDriver="com.mysql.cj.jdbc.Driver";
            MySqIURL=
                    "jdbc:mysql://localhost:3306/sky?user=root&password=mySQL123456" ;
//        "&Unicode=true&characterEncoding=utf-8";
            Class.forName(MySqlIDriver).newInstance();
            conn= DriverManager.getConnection(MySqIURL);
        }catch (Exception e){
            e.printStackTrace();
        }
        return  conn;
    }



}
